import connDB

##根据dwd建表语句，创建dm表建表语句，修改表名即可
def dwdToDmTableName(dwdSchema, dwdTableName,dmSchema,dmTableName,attibutes):
    # 创建连接
    connDwd = connDB.create_connection(**connDB.dwr_prd_config)
    connDm = connDB.create_connection(**connDB.dm_prd_config)
    if connDwd and connDm:
        queryDwdCreateTable = f"select pg_get_tabledef('{dwdSchema}.{dwdTableName}');"
        dwdCreateTable=connDB.fetch_data(connDwd, queryDwdCreateTable)
        if dwdCreateTable:
            dmCreateTable = dwdCreateTable[0][0]
            dmCreateTable = dmCreateTable.replace(dwdSchema,dmSchema,1)
            dmCreateTable = dmCreateTable.replace(dwdTableName,dmTableName)
            print(dmCreateTable)

        connDwd.close()
        connDm.close()
        print("数据库连接已关闭")
if __name__ == "__main__":
    #dwd schema
    dwdschema = "itg"
    # dm schema
    dmSchema= 'common_dm'
    #dwd 表名
    dwdTableName="dwd_ft_itg_asset_behav_spdng_expns_detil_d_f"
    # dm 表名
    dmTableName="dm_ft_itg_asset_behav_spdng_expns_detil_d_f"
    # 需要删除的dm字段
    attibutes=[]
    dwdToDmTableName(dwdschema,dwdTableName,dmSchema,dmTableName,attibutes)